package Wlecome;
import java.io.*;
import java.util.*;
public class Test3 {
public static void main(String args[]) {
	File file = new File("C:\\Users\\GEK\\Desktop\\student.txt");
	Scanner sc = null;
	FileWriter fw = null;
	int count = 0;
	double sum = 0;
	try { double score = 0;
	    sc = new Scanner(file);
	    sc.useDelimiter("[^0123456789.]+");
	    while(sc.hasNextDouble()) {
		    score = sc.nextDouble();
		    count++;
		    sum = sum + score;
		
		    System.out.println(score);
	    }
	    double aver = sum/count;
	    String str = String.format("%.3f", aver);
	    System.out.println("平均价格为:"+str);    
        fw = new FileWriter(file, true); 
        fw.write(System.lineSeparator());  
        fw.write(str);
        }
	catch (Exception exp) {  
        System.out.println("发生错误: " + exp.getMessage());  
    }
	finally {    
        if (sc != null) {  
            sc.close();  
        }  
        if (fw != null) {  
            try {  
                fw.close();  
            } 
            catch (IOException e) {  
                System.out.println(e.getMessage());  
            }  
        }  
    } 
}
}